package model;

import DataBase.OraConnection;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class PengendaliPendaftaranYudisium {

    public static ArrayList<Yudisium> DAFTAR_MAHASISWA = new ArrayList<Yudisium>();

    public static void tambahMahasiswa(Yudisium yudisium) {
        DAFTAR_MAHASISWA.add(yudisium);
    }

    public static void tambahTabelMahasiswa(Yudisium yudisium) {
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl","MHS115314020", "MHS115314020");
        Statement statement = null;
        try {
            statement = conn.createStatement();
            String sql = "insert into yudisium (nama, nim, nomor_hp, prodi,email,  periode_bulan," +
                                                "periode_hari, periode_tanggal,persetujuan_nilai,"
                                                + "pengesahan_skripsi, bebaspinjam_lab, bebaspinjam_dosen,"
                                                + "bukti_kp, fotocopy_tkbi, fotocopy_ta, "
                                                + "sistem_poin, bukti_rbm, status) values ('"
                                                + yudisium.getNama() + "','" + yudisium.getNim() + "','"
                                                + yudisium.getNoHp() + "','" + yudisium.getProdi() + "','" + yudisium.getEmail() + "','"
                                                + yudisium.getPeriode() + "','"
                                                + yudisium.getHari() + "','" + yudisium.getTanggal()+ "','"
                                                + yudisium.getPersetujuan_nilai() + "','"
                                                + yudisium.getPengesahan_skripsi() + "','"
                                                + yudisium.getBebaspinjam_lab() + "','"
                                                + yudisium.getBebaspinjam_dosen() + "','"
                                                + yudisium.getBukti_kp() + "','" + yudisium.getFotocopy_tkbi() + "','"
                                                + yudisium.getFotocopy_ta() + "','"
                                                + yudisium.getSistem_poin() + "','" + yudisium.getBukti_rbm()
                                                + "','" + yudisium.getStatus()
                                                + "')";
            //System.out.println(sql);
            statement.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void lihatTabelMahasiswa() {
        PengendaliPendaftaranYudisium.DAFTAR_MAHASISWA = new ArrayList<Yudisium>();
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl","MHS115314020", "MHS115314020");
        java.sql.Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sqQ = "select * from yudisium";
        ResultSet result = null;
        try {
            result = statement.executeQuery(sqQ);
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (result.next()) {
                Yudisium temp = new Yudisium();
                temp.setNama(result.getString("nama"));
                temp.setNim(result.getString("nim"));
                temp.setNoHp(result.getString("nomor_hp"));
                temp.setProdi(result.getString("prodi"));
                temp.setEmail(result.getString("email"));
                temp.setPeriode(result.getString("periode_bulan"));
                temp.setHari(result.getString("periode_hari"));
                temp.setTanggal(result.getInt("periode_tanggal"));
                temp.setPersetujuan_nilai(result.getString("persetujuan_nilai"));
                temp.setPengesahan_skripsi(result.getString("pengesahan_skripsi"));
                temp.setBebaspinjam_lab(result.getString("bebaspinjam_lab"));
                temp.setBebaspinjam_dosen(result.getString("bebaspinjam_dosen"));
                temp.setBukti_kp(result.getString("bukti_kp"));
                temp.setFotocopy_tkbi(result.getString("fotocopy_tkbi"));
                temp.setFotocopy_ta(result.getString("fotocopy_ta"));
                temp.setSistem_poin(result.getString("sistem_poin"));
                temp.setBukti_rbm(result.getString("bukti_rbm"));
                temp.setStatus(result.getString("status"));
                PengendaliPendaftaranYudisium.DAFTAR_MAHASISWA.add(temp);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            conn.close();
        } catch (SQLException ex) {
        }
    }
}
